﻿package main 
{
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author ...
	 */
	public class Flag {
		
		public function Flag(x:Number, y:Number) {
			this.x = x;
			this.y = y;
		}
		
		private var x:Number;
		public function getX():Number {
			return x;
		}
		private var y:Number;
		public  function getY():Number {
			return y;
		}
		
		public function updateSpriteCircle(sprite:Sprite, yacht:Yacht, dx:Number, dy:Number):void {
			var flagDist:Number = Math.sqrt(dx * dx + dy * dy);
			if (flagDist > 200) {
				flagDist = 200;
				sprite.scaleX = sprite.scaleY = Math.max(0.2, 1 - (flagDist - 200));
			} else {
				sprite.scaleX = sprite.scaleY = 1;
			}
			var a:Number = Math.atan2( -dy, dx) - (yacht.getAngle() * Math.PI / 180);
			sprite.x = yacht.sprite.x + flagDist * Math.cos(a);
			sprite.y = yacht.sprite.y - flagDist * Math.sin(a);
		}
		
		public function updateSpriteQuarter(sprite:Sprite, yacht:Yacht, dx:Number, dy:Number):void {
			var flagDist:Number = Math.sqrt(dx * dx + dy * dy);
			if (flagDist > 200) {
				sprite.scaleX = sprite.scaleY = 1 - Math.min(600, flagDist - 200) / 600;
			} else {
				sprite.scaleX = sprite.scaleY = 1;
			}
			var a:Number = Math.atan2( -dy, dx) - (yacht.getAngle() * Math.PI / 180);
			sprite.x = yacht.sprite.x + flagDist * Math.cos(a);
			sprite.y = yacht.sprite.y - flagDist * Math.sin(a);
		}
		
	}
	
}